import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);
import stock from './stock.js';
import molle2 from './molle2.js';

export default new Vuex.Store({
  modules: {
    stock, //股票对象
    molle2, //测试模块2
  },
  state: {
    TOKEN: null,
    msg: { name: 'a123' },
    winSize: [],
  },
  getters: {
    getValue: (state) => (key) => {
      return state[key];
    },
    getTOKEN: (state) => {
      if (state.TOKEN === null) {
        state.TOKEN = localStorage.getItem('TOKEN') || null;
      }
      return state.TOKEN;
    },
    getPXbyVW: (state) => (vw) => {
      return (state.winSize[0] / 100) * vw;
    },
    getPXbyVH: (state) => (vh) => {
      return (state.winSize[1] / 100) * vh;
    },
  },
  mutations: {
    setValue: (state, obj) => {
      state[obj.key] = obj.value;
    },
    setLocal: (state, value) => {
      state.key = value;
      localStorage.setItem('key', value);
    },
    setWinSize: (state) => {
      state.winSize[0] = window.innerWidth;
      state.winSize[1] = window.innerHeight;
    },
  },
  actions: {},
});
